package com.alangyun.remind.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alangyun.remind.error.MindException;
import com.alangyun.remind.service.ITalentService;
import com.alangyun.remind.service.IUploadService;
import com.alangyun.remind.vo.DataResponse;
import com.alangyun.remind.vo.ErrorCode;
import com.alangyun.remind.vo.FilterParam;
import com.alangyun.remind.vo.Response;
import com.alangyun.remind.vo.talent.AbilityUserView;
import com.alangyun.remind.vo.talent.AbilityView;
import com.alangyun.remind.vo.talent.AgeYearsView;
import com.alangyun.remind.vo.talent.SudokuView;
import com.alangyun.remind.vo.talent.TrendView;

@Controller
public class TalentController extends AbstractController {
	@Resource
	private IUploadService svcUpload;
	@Resource
	private ITalentService svcData;

	@PostMapping(value = Paths.TalentUrl.TALENT_UPLOAD)
	@ResponseBody
	public Response talentUpload(@RequestParam("file") MultipartFile file) {
		Response ret = new Response();
		try {
			validateTimeout();
			
			svcUpload.parseTalentFile(file);
			ret.setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc("上传人才开发数据预警数据处理失败");
			e("上传人才开发数据预警数据处理失败", ex);
		}
		return ret;
	}

	@PostMapping(value = Paths.TalentUrl.TALENT_NAV_TREE)
	@ResponseBody
	public DataResponse<FilterParam> categories() {
		DataResponse<FilterParam> ret = new DataResponse<FilterParam>();
		try {
			validateTimeout();
			
			ret.setData(svcData.categories());
			ret.setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc("提取过滤参数失败");
			e("提取过滤参数失败", ex);
		}

		return ret;
	}

	/**
	 * 专业化能力预警
	 *
	 * @author hoobort klxukun@126.com
	 * @company 北京诚朗信息技术有限公司
	 * @datetime 2022年11月10日 下午1:35:32
	 * @return
	 */
	@RequestMapping(value = Paths.TalentUrl.TALENT_PROFECIAL11, method = { RequestMethod.GET, RequestMethod.POST })
	public String professionalPage11(Model model) {
		String ret = "/mind/talent-professional-1-1";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.talentTypes());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.TALENT_PROFESSION);
		} catch (MindException me) {
			ret = pageError(model, me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret = pageError(model, "打开专业化能力预警管理页面出错了，可能原因 " + ex.getMessage());
			e("打开专业化能力预警管理页面出错", ex);
		}
		return ret;
	}

	@RequestMapping(value = Paths.TalentUrl.TALENT_PROFECIAL12, method = { RequestMethod.GET, RequestMethod.POST })
	public String professionalPage12(Model model) {
		String ret = "/mind/talent-professional-1-2";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.talentTypes());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.TALENT_PROFESSION);
		} catch (MindException me) {
			ret = pageError(model, me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret = pageError(model, "打开专业化能力预警管理页面出错了，可能原因 " + ex.getMessage());
			e("打开专业化能力预警管理页面出错", ex);
		}

		return ret;
	}

	@RequestMapping(value = Paths.TalentUrl.TALENT_PROFECIAL13, method = { RequestMethod.GET, RequestMethod.POST })
	public String professionalPage13(Model model) {
		String ret = "/mind/talent-professional-1-3";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.talentTypes());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.TALENT_PROFESSION);
		} catch (MindException me) {
			ret = pageError(model, me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret = pageError(model, "打开专业化能力预警管理页面出错了，可能原因 " + ex.getMessage());
			e("打开专业化能力预警管理页面出错", ex);
		}
		return ret;
	}

	@PostMapping(value = Paths.TalentUrl.TALENT_PROFECIAL11_LIST)
	@ResponseBody
	public DataResponse<AbilityView> listProf11(@RequestParam(value = "size", defaultValue = "15") int size) {
		DataResponse<AbilityView> ret = new DataResponse<AbilityView>();
		try {
			validateTimeout();
			
			ret.setData(svcData.listBySize(size)).setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.INNER_ERROR).setDesc("列出专业能力预警数据失败");
			e("列出专业能力预警数据失败", ex);
		}

		return ret;
	}

	@PostMapping(value = Paths.TalentUrl.TALENT_PROFECIAL11_QUERY_DEPART)
	@ResponseBody
	public DataResponse<AbilityView> queryProfOfDepart(
			@RequestParam(value = "team", required = false) Integer[] teams,
			@RequestParam(value = "prof", required = false) Integer[] profs,
			@RequestParam(value = "job", required = false) Integer[] jobs) {
		DataResponse<AbilityView> ret = new DataResponse<AbilityView>();
		try {
			validateTimeout();
			
			ret.setData(svcData.listByDepart(teams, profs, jobs)).setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.INNER_ERROR).setDesc("列出专业能力预警数据失败");
			e("列出专业能力预警数据失败", ex);
		}

		return ret;
	}

	@PostMapping(value = Paths.TalentUrl.TALENT_PROFECIAL11_QUERY_PROF)
	@ResponseBody
	public DataResponse<AbilityView> queryProfOfProf(
			@RequestParam(value = "team", required = false) Integer[] teams,
			@RequestParam(value = "prof", required = false) Integer[] profs,
			@RequestParam(value = "job", required = false) Integer[] jobs) {
		DataResponse<AbilityView> ret = new DataResponse<AbilityView>();
		try {
			validateTimeout();
			
			ret.setData(svcData.listByProf(teams, profs, jobs)).setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.INNER_ERROR).setDesc("列出专业能力预警数据失败");
			e("列出专业能力预警数据失败", ex);
		}

		return ret;
	}

	@PostMapping(value = Paths.TalentUrl.TALENT_PROFECIAL11_QUERY_CLASS)
	@ResponseBody
	public DataResponse<AbilityView> queryProfByClass(
			@RequestParam(value = "team", required = false) Integer[] teams,
			@RequestParam(value = "prof", required = false) Integer[] profs,
			@RequestParam(value = "job", required = false) Integer[] jobs) {
		DataResponse<AbilityView> ret = new DataResponse<AbilityView>();
		try {
			validateTimeout();
			
			ret.setData(svcData.listByClass(teams, profs, jobs)).setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.INNER_ERROR).setDesc("列出专业能力预警数据失败");
			e("列出专业能力预警数据失败", ex);
		}

		return ret;
	}

	/**
	 * 九宫格分类结构预警
	 *
	 * @author hoobort klxukun@126.com
	 * @company 北京诚朗信息技术有限公司
	 * @datetime 2022年11月10日 下午1:35:38
	 * @return
	 */
	@RequestMapping(value = Paths.TalentUrl.TALENT_SUDOKU11, method = { RequestMethod.GET, RequestMethod.POST })
	public String sudokuPage11(Model model) {
		String ret = "/mind/talent-sudoku-1-1";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.talentTypes());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.TALENT_SUDOKU);
		} catch (MindException me) {
			ret = pageError(model, me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret = pageError(model, "打开九宫格预警管理页面失败，可能原因 " + ex.getMessage());
			e("打开九宫格预警管理页面失败", ex);
		}

		return ret;
	}

	@RequestMapping(value = Paths.TalentUrl.TALENT_SUDOKU12, method = { RequestMethod.GET, RequestMethod.POST })
	public String sudokuPage12(Model model) {
		String ret = "/mind/talent-sudoku-1-2";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.talentTypes());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.TALENT_SUDOKU);
		} catch (MindException me) {
			ret = pageError(model, me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret = pageError(model, "打开九宫格预警管理页面失败，可能原因 " + ex.getMessage());
			e("打开九宫格预警管理页面失败", ex);
		}

		return ret;
	}

	@PostMapping(value = Paths.TalentUrl.TALENT_SUDOKU11_LIST)
	@ResponseBody
	public DataResponse<List<SudokuView>> listSudoku11(@RequestParam(value = "size", defaultValue = "15") int size) {
		DataResponse<List<SudokuView>> ret = new DataResponse<List<SudokuView>>();
		try {
			validateTimeout();
			
			ret.setData(svcData.listSudokuBySize(size)).setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.INNER_ERROR).setDesc("列出九宫格预警数据失败");
			e("列出九宫格预警数据失败", ex);
		}

		return ret;
	}

	@PostMapping(value = Paths.TalentUrl.TALENT_SUDOKU12_QUERY)
	@ResponseBody
	public DataResponse<List<SudokuView>> querySudoku12(
			@RequestParam(value = "team", required = false) Integer[] teams,
			@RequestParam(value = "prof", required = false) Integer[] profs,
			@RequestParam(value = "job", required = false) Integer[] jobs) {
		DataResponse<List<SudokuView>> ret = new DataResponse<List<SudokuView>>();
		try {
			validateTimeout();
			
			ret.setData(svcData.listSudoku(teams, profs, jobs)).setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.INNER_ERROR).setDesc("列出九宫格预警数据失败");
			e("列出九宫格预警数据失败", ex);
		}

		return ret;
	}

	/**
	 * 专业能力红绿灯预警
	 *
	 * @author hoobort klxukun@126.com
	 * @company 北京诚朗信息技术有限公司
	 * @datetime 2022年11月10日 下午1:35:44
	 * @return
	 */
	@RequestMapping(value = Paths.TalentUrl.TALENT_TRAFIC, method = { RequestMethod.GET, RequestMethod.POST })
	public String traficPage(Model model) {
		String ret = "/mind/talent-trafic";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.talentTypes());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.TALENT_TRAFIC);
		} catch (MindException me) {
			ret = pageError(model, me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret = pageError(model, "打开红绿灯预警管理页面失败，可能原因 " + ex.getMessage());
			e("打开红绿灯预警管理页面失败", ex);
		}

		return ret;
	}

	@PostMapping(value = Paths.TalentUrl.TALENT_TRAFIC_LIST)
	@ResponseBody
	public DataResponse<List<AbilityUserView>> listTrafic(@RequestParam(value = "size", defaultValue = "15") int size) {
		DataResponse<List<AbilityUserView>> ret = new DataResponse<List<AbilityUserView>>();
		try {
			validateTimeout();
			
			ret.setData(svcData.listTraficBySize(size)).setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.INNER_ERROR).setDesc("列出专业能力红绿灯预警数据失败");
			e("列出专业能力红绿灯预警数据失败", ex);
		}

		return ret;
	}

	@PostMapping(value = Paths.TalentUrl.TALENT_TRAFIC_QUERY)
	@ResponseBody
	public DataResponse<List<AbilityUserView>> queryTrafic(
			@RequestParam(value = "team", required = false) Integer[] teams,
			@RequestParam(value = "prof", required = false) Integer[] profs,
			@RequestParam(value = "job", required = false) Integer[] jobs) {
		DataResponse<List<AbilityUserView>> ret = new DataResponse<List<AbilityUserView>>();
		try {
			validateTimeout();
			
			ret.setData(svcData.listTrafic(teams, profs, jobs)).setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.INNER_ERROR).setDesc("列出专业能力红绿灯预警数据失败");
			e("列出专业能力红绿灯预警数据失败", ex);
		}

		return ret;
	}

	@RequestMapping(value = Paths.TalentUrl.TALENT_TRAFIC_PROFILE, method = { RequestMethod.GET, RequestMethod.POST })
	public String traficProfilePage(Model model, @RequestParam("id")String id) {
		String ret = "/mind/talent-trafic-profile";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.talentTypes());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.TALENT_TRAFIC);
			model.addAttribute("user", svcData.findUser(id));
		} catch (MindException me) {
			ret = pageError(model, me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret = pageError(model, "打开红绿灯预警管理页面失败，可能原因 " + ex.getMessage());
			e("打开红绿灯预警管理页面失败", ex);
		}

		return ret;
	}

	/**
	 * 人才队伍趋势预警
	 *
	 * @author hoobort klxukun@126.com
	 * @company 北京诚朗信息技术有限公司
	 * @datetime 2022年11月10日 下午1:35:56
	 * @return
	 */
	@RequestMapping(value = Paths.TalentUrl.TALENT_TEAM11, method = { RequestMethod.GET, RequestMethod.POST })
	public String teamPage11(Model model) {
		String ret = "/mind/talent-team-1-1";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.talentTypes());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.TALENT_TEAM);
		} catch (MindException me) {
			ret = pageError(model, me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret = pageError(model, "打开人才队伍预警管理页面失败，可能原因 " + ex.getMessage());
			e("打开人才队伍预警管理页面失败", ex);
		}

		return ret;
	}

	@RequestMapping(value = Paths.TalentUrl.TALENT_TEAM12, method = { RequestMethod.GET, RequestMethod.POST })
	public String teamPage12(Model model) {
		String ret = "/mind/talent-team-1-2";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.talentTypes());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.TALENT_TEAM);
		} catch (MindException me) {
			ret = pageError(model, me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret = pageError(model, "打开人才队伍预警管理页面失败，可能原因 " + ex.getMessage());
			e("打开人才队伍预警管理页面失败", ex);
		}

		return ret;
	}

	@RequestMapping(value = Paths.TalentUrl.TALENT_TEAM13, method = { RequestMethod.GET, RequestMethod.POST })
	public String teamPage13(Model model) {
		String ret = "/mind/talent-team-1-3";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.talentTypes());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.TALENT_TEAM);
		} catch (MindException me) {
			ret = pageError(model, me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret = pageError(model, "打开人才队伍预警管理页面失败，可能原因 " + ex.getMessage());
			e("打开人才队伍预警管理页面失败", ex);
		}

		return ret;

	}

	@RequestMapping(value = Paths.TalentUrl.TALENT_TEAM14, method = { RequestMethod.GET, RequestMethod.POST })
	public String teamPage14(Model model) {
		String ret = "/mind/talent-team-1-4";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.talentTypes());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.TALENT_TEAM);
		} catch (MindException me) {
			ret = pageError(model, me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret = pageError(model, "打开人才队伍预警管理页面失败，可能原因 " + ex.getMessage());
			e("打开人才队伍预警管理页面失败", ex);
		}

		return ret;
	}

	/**
	 * 中青年龄结构预警
	 *
	 * @author hoobort klxukun@126.com
	 * @company 北京诚朗信息技术有限公司
	 * @datetime 2022年11月10日 下午1:36:02
	 * @return
	 */
	@RequestMapping(value = Paths.TalentUrl.TALENT_YOUNG, method = { RequestMethod.GET, RequestMethod.POST })
	public String youngPage(Model model) {
		String ret = "/mind/talent-young";
		try {
			validateTimeout();
			
//			model.addAttribute("navigate", svcData.talentTypes());
			model.addAttribute(CategoryIdentities.VARIABLE, CategoryIdentities.TALENT_YOUNG);
		} catch (MindException me) {
			ret = pageError(model, me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret = pageError(model, "打开中青年龄结构预警管理页面失败，可能原因 " + ex.getMessage());
			e("打开中青年龄结构预警管理页面失败", ex);
		}

		return ret;
	}

	@PostMapping(value = Paths.TalentUrl.TALENT_YOUNG_LIST)
	@ResponseBody
	public DataResponse<List<AgeYearsView>> queryYoung(@RequestParam(value = "team", required = false) Integer[] teams,
			@RequestParam(value = "prof", required = false) Integer[] profs,
			@RequestParam(value = "job", required = false) Integer[] jobs) {
		DataResponse<List<AgeYearsView>> ret = new DataResponse<List<AgeYearsView>>();
		try {
			validateTimeout();
			
			ret.setData(svcData.listAgeRatio(teams, profs, jobs)).setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.INNER_ERROR).setDesc("列出中青年年龄结构预警数据失败");
			e("列出中青年年龄结构预警数据失败", ex);
		}

		return ret;
	}

	@PostMapping(value = Paths.TalentUrl.TALENT_TEAM_SUM)
	@ResponseBody
	public DataResponse<TrendView> queryTeam(
			@RequestParam("tp")int type,
			@RequestParam(value = "team", required = false) Integer[] teams,
			@RequestParam(value = "prof", required = false) Integer[] profs,
			@RequestParam(value = "job", required = false) Integer[] jobs) {
		DataResponse<TrendView> ret = new DataResponse<TrendView>();
		try {
			validateTimeout();
			
			ret.setData(svcData.listTrend(type, teams, profs, jobs)).setCode(ErrorCode.SUCCESS);
		} catch (MindException me) {
			ret.setCode(ErrorCode.EXCEPTION).setDesc(me.getMessage());
			e(me.getMessage(), me);
		} catch (Exception ex) {
			ret.setCode(ErrorCode.INNER_ERROR).setDesc("列出人才趋势预警数据失败");
			e("列出人才趋势预警数据失败", ex);
		}

		return ret;
	}

}
